def ones_and_zeros(strs, m, n):
    l = len(strs)
    # dp l*m*n
    dp = [[[0] * (n + 1) for _ in range(m + 1)] for _ in range(l + 1)]
    # i,j,k -> l, m, n
    for i in range(1, l+1):
        str = strs[i-1]
        zeros, ones = str.count('0'), str.count('1')
        for j in range(m+1):
            for k in range(n+1):
                if j>=zeros and k>=ones:
                    dp[i][j][k] = max(dp[i-1][j][k], dp[i-1][j-zeros][k-ones]+1)
                else:
                    dp[i][j][k] = dp[i-1][j][k]

    return dp[-1][-1][-1]

print(ones_and_zeros(["10", "0001", "111001", "1", "0"], 5, 3))
print(ones_and_zeros(["10", "0", "1"], 1, 1))